In [1]:
# TensorBoard Helper Functions and Constants

# Directory to export TensorBoard summary statistics, graph data, etc.
TB_DIR = '/tmp/tensorboard/helloworld'


def _start_tb(d):
    """
    Private function that calls `tensorboard` shell command
    
    args:
      d: The desired directory to launch in TensorBoard
    """
    !tensorboard --port=6006 --logdir=$d

def start_tensorboard():
    """
    Starts TensorBoard from the notebook in a separate thread.
    Prevents Jupyter Notebook from halting while TensorBoard runs.
    """
    import threading
    threading.Thread(target=_start_tb, args=(TB_DIR,)).start()
    del threading

def stop_tensorboard():
    """
    Kills all TensorBoard processes
    """
    !ps -aef | grep "tensorboard" | tr -s ' ' | cut -d ' ' -f2 | xargs kill -KILL
    
def reset_tensorboard():
    stop_tensorboard()
    start_tensorboard()

In [2]:
import tensorflow as tf

In [3]:
helloworld = tf.constant('Hello, Spark Experts!')

In [4]:
sess = tf.Session()

In [5]:
tf.train.SummaryWriter('/tmp/tensorboard/helloworld', sess.graph)


Out[5]:
<tensorflow.python.training.summary_io.SummaryWriter at 0x7fb9791e7fd0>

In [6]:
print sess.run(helloworld)


Hello, Spark Experts!

In [2]:
!tensorboard --port=6006 --logdir=/tmp/tensorboard/helloworld


WARNING:tensorflow:Found more than one graph event per run. Overwriting the graph with the newest event.
WARNING:tensorflow:Found more than one graph event per run. Overwriting the graph with the newest event.
WARNING:tensorflow:Found more than one graph event per run. Overwriting the graph with the newest event.
Starting TensorBoard 16 on port 6006
(You can navigate to http://0.0.0.0:6006)
^C
Traceback (most recent call last):
  File "/usr/local/bin/tensorboard", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/tensorboard/tensorboard.py", line 108, in main
    tb_server.serve_forever()
  File "/usr/lib/python2.7/SocketServer.py", line 236, in serve_forever
    poll_interval)
  File "/usr/lib/python2.7/SocketServer.py", line 155, in _eintr_retry
    return func(*args)
KeyboardInterrupt
  • Ignore "No scalar data was found" error for now
  • We're simply testing connectivity

Stop TensorBoard for now


In [3]:
!ps -aef | grep "tensorboard" | tr -s ' ' | cut -d ' ' -f2 | xargs kill -KILL

In [ ]: